package persistence.rmi;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.util.Properties;

public class RMIServer {

	private static Properties props;

	static {
		FileInputStream fis;
		try {
			props = new Properties();
			fis = new FileInputStream("bin/persistence/rmi/props.properties");
			props.load(fis);
		} catch (FileNotFoundException e) {
			System.err.println(e.getMessage());
			e.printStackTrace();
		} catch (IOException e) {
			System.err.println(e.getMessage());
			e.printStackTrace();
		}
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		@SuppressWarnings("unused")
		RMIServer server = new RMIServer();
		System.out.println("#RmiServer started#");	
	}

	public RMIServer() {
		int port = Integer.parseInt(props.getProperty("port.rmi"));
		try {
			Registry annuaire = LocateRegistry.createRegistry(port);
			IntegrationRemote service = new IntegrationRmiService();
			String urlService = props.getProperty("url.service");
			annuaire.rebind(urlService, service);
		} catch (RemoteException e) {
			System.err.println(e.getMessage());
			e.printStackTrace();
		}
	}
}
